#pragma once

#include <iostream>
#include <string>

#include "Reactor.hpp"
#include "InetAddr.hpp"


class Reactor;
class Channel;

using handler_t = std::function<std::string (std::string &)>;

class Connection
{
public:
    Connection() : _events(0), _owner(nullptr)
    {
    }

    virtual void Recver() = 0;   // 接收数据虚函数
    virtual void Sender() = 0;   // 发送数据虚函数
    virtual void Excepter() = 0; // 异常处理虚函数
    virtual int GetSockFd() = 0; // 获取sockfd虚函数

    void SetEvents(uint32_t events) { _events = events; } // 设置关心事件
    uint32_t GetEvents() { return _events; }              // 获取关心事件
    void SetOwner(Reactor *owner) { _owner = owner; }     // 设置所属TcpServer
    Reactor *GetOwner() { return _owner; }                // 获取所属TcpServer

    void RegsiterHandler(handler_t handler)
    {
        _handler = handler;
    }

    ~Connection()
    {
    }

private:
    Reactor *_owner;  // 回指指针
    uint32_t _events; // 关心事件

public:
    handler_t _handler; // 事件处理函数
};
